package cn.wolfcode.crm.service.imp;

import cn.wolfcode.crm.domain.Recruitplan;
import cn.wolfcode.crm.mapper.RecruitplanMapper;
import cn.wolfcode.crm.qo.PageResult;
import cn.wolfcode.crm.qo.RecruitPlanQueryObject;
import cn.wolfcode.crm.service.IRecruitPlanService;
import cn.wolfcode.crm.util.UserContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collections;

@Service
public class RecruitPlanServiceImpl implements IRecruitPlanService {

    @Autowired
    private RecruitplanMapper recruitplanMapper;

    @Override
    public void deleteByPrimaryKey(Long id) {
        recruitplanMapper.deleteByPrimaryKey(id);
    }

    @Override
    public void insert(Recruitplan record) {
        recruitplanMapper.insert(record);
    }


    @Override
    public PageResult query(RecruitPlanQueryObject qo) {
        int rows = recruitplanMapper.rows(qo);
        if (rows == 0) {
            return PageResult.EMPTY_RESULT;
        }
            return new PageResult(rows, recruitplanMapper.queryForList(qo));

    }

    @Override
    public void changeState(Long id) {
        Recruitplan recruitplan = recruitplanMapper.selectByPrimaryKey(id);
        if (recruitplan.isStatus()) {
            throw new RuntimeException("请选择未审核数据!");
        }

        recruitplan.setStatus(true);
        recruitplan.setAuditMan(UserContext.getCurrentUser().getUsername());
        recruitplanMapper.changeState(recruitplan);
    }

    @Override
    public void updateByPrimaryKey(Recruitplan record) {
        recruitplanMapper.updateByPrimaryKey(record);
    }
}
